package com.jdkreader.concurrency.concurrent.performance;

/**
 * 耗时计算工具类
 */
public class SimpleMicroBeenchMark {

    public static long test(Incrementable inc){
        long start=System.nanoTime();
        for(int i=0;i<1000000L;i++){
            inc.increment();
        }
        return System.nanoTime() - start;
    }

    public static void main(String[] args) {
        long syncTime=test(new SynchronizedTest());
        long lockTime=test(new LockingTest());
        System.out.println("Synchronized Time: "+syncTime);
        System.out.println("Lock Time: "+lockTime);
        System.out.println("Lock/Synchronized: "+(syncTime/lockTime));
    }
}
